package poiTests;



import com.thoughtworks.selenium.*;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import org.junit.Before;
import org.junit.Test;

public class SeleniumTest  extends SeleneseTestCase {

	@Before
	public void setUp() throws Exception {
		setUp("http://localhost:8080/GeoServlet/", "*chrome");
	}
	
	@Test
	public void testGeoServlet()  {
		selenium.open("/GeoServlet/");
		selenium.click("link=Data from CSV file");
		selenium.waitForPageToLoad("30000");
		assertEquals(false, selenium.isTextPresent("Error reading from CSV file!"));
		assertTrue(selenium.getBodyText().split("<br>").length>0);
		assertEquals(0,(selenium.getBodyText().replaceAll("\n", ",").split(",").length)%5);	
        BufferedReader in;
        String fileContent = new String();
        fileContent = "";        
        try {
            in = new BufferedReader(new InputStreamReader(new FileInputStream("WebContent/poidata.csv")));
            while (in.ready()) {
            	fileContent += in.readLine();
            	if (in.ready()) fileContent += "\n";
            }
            in.close();
        } catch (IOException e) {
        	fail("Error reading file!");
        }
        assertEquals(selenium.getBodyText(), fileContent);
	}

}
